package com.zeroxml.cms.web.action.admin;

import com.zeroxml.cms.web.action.BaseAction;
import net.sourceforge.stripes.action.DefaultHandler;
import net.sourceforge.stripes.action.Resolution;
import net.sourceforge.stripes.action.RedirectResolution;
import net.sourceforge.stripes.action.UrlBinding;
import org.apache.commons.lang.StringUtils;

/**
 * User: cjp
 * Date: 2007-9-9
 * Time: 20:33:54
 */
@UrlBinding("/admin/login.do")
public class LoginAction extends BaseAction {
    private String name;
    private String password;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @DefaultHandler
    public Resolution login(){
        if(StringUtils.equalsIgnoreCase(name,"admin")&&StringUtils.equalsIgnoreCase(password,"1")){
            actionBeanContext.getRequest().getSession().setAttribute("admin","admin");
            return new RedirectResolution(ControlAction.class);
        }else{
            return getAdminResolution("index");
        }
    }

    public Resolution logout(){
        actionBeanContext.getRequest().getSession().invalidate();
        return new RedirectResolution(IndexAction.class);
    }
}
